/* define local variable*/ InputStream in =null; SqlSession sqlSession=null; /* read xml file and make initial configuration */ try in = Resources.getResourceAsStream("mybatis-config.xml"); sqlSession = new SqlSessionFactoryBuilder().build(in).openSession(); catch(IOException ioe) return;
/* get user data from sqlSession */ IUserDao iUserDao = sqlSession.getMapper(IUserDao.class); List list =iUserDao.findAll(); for (User user:list) System.out.println(user);
/* database reading finished, close everything peacefully */ try in.close(); catch(IOException ioe) System.out.println("exception happened in in.close()");
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
10、所有配置文件文件都准备好后,结构如下所示,
11、利用maven-》“Hello”-》“Lifecycle”-》“compile”进行编译
12、到了这一步,就可以开始运行App.class文件了,
执行过程中,如果有弹窗,选择“Hello”即可,
不出意外的话,就可以看到这样的打印信息,
"C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\bin\\java.exe" "-javaagent:C:\\Program Files\\JetBrains\\IntelliJ IDEA 2020.1.1\\lib\\idea_rt.jar=59510:C:\\Program Files\\JetBrains\\IntelliJ IDEA 2020.1.1\\bin" -Dfile.encoding=UTF-8 -classpath "C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\charsets.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\deploy.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\access-bridge-32.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\cldrdata.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\dnsns.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\jaccess.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\jfxrt.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\localedata.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\nashorn.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\sunec.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\sunjce_provider.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\sunmscapi.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\sunpkcs11.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\ext\\zipfs.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\javaws.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\jce.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\jfr.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\jfxswt.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\jsse.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\management-agent.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\plugin.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\resources.jar;C:\\Program Files (x86)\\Java\\jdk1.8.0_91\\jre\\lib\\rt.jar;C:\\Users\\feixiaoxing\\Desktop\\Hello\\target\\classes;D:\\software\\apache-maven-3.6.3-bin\\repository\\org\\mybatis\\mybatis\\3.4.5\\mybatis-3.4.5.jar;D:\\software\\apache-maven-3.6.3-bin\\repository\\mysql\\mysql-connector-java\\5.1.47\\mysql-connector-java-5.1.47.jar" org.example.App Sat Oct 08 06:52:56 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Userid=1, name='tom', birthday=Sat Oct 08 06:13:03 CST 2022, sex='m', address='china' Process finished with exit code 0